package com.victor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.victor.entity.city.CityIntroduce;
import com.victor.entity.city.CityIntroduceComment;
import com.victor.entity.city.CityIntroduceCommentPhoto;
import com.victor.entity.city.CityIntroduceCommentPraise;
import com.victor.entity.city.CityIntroduceCommentReply;
import com.victor.entity.city.CityIntroducePhoto;
import com.victor.entity.city.CityIntroducePraise;

@Mapper
public interface CityDao {

	/**
	 * 传入城市名称获取城市介绍
	 * 
	 * @param city
	 * @return
	 */
	CityIntroduce getCityMessage(String city);

	/**
	 * 添加评论城市
	 * 
	 * @param cityIntroduceComment
	 * @return
	 */
	boolean commentCity(CityIntroduceComment cityIntroduceComment);

	/**
	 * 添加评论城市的图片
	 * 
	 * @param cityIntroduceCommentPhoto
	 * @return
	 */
	@Insert({ "insert into c_cityintroduce_comment_photo (ccp_photopath,cc_id) values(#{ccp_photopath},#{cc_id})" })
	boolean commentCityPhoto(CityIntroduceCommentPhoto cityIntroduceCommentPhoto);

	/**
	 * 根据城市介绍id获取点赞数
	 * 
	 * @param c_id
	 * @return
	 */
	@Select({ "select count(*) from c_cityintroduce_praise where c_id=#{c_id}" })
	int getPraisenumber(Integer c_id);

	/**
	 * 根据城市评论回复获取点赞数
	 * 
	 * @param c_id
	 * @return
	 */
	@Select({ "select count(*) from c_cityintroduce_comment_reply where ccr_id=#{ccr_id}" })
	int getCommentPraisenumber(Integer ccr_id);

	/**
	 * 回复评论
	 * 
	 * @param cityIntroduceCommentReply
	 * @return
	 */
	@Insert({
			"insert into c_cityintroduce_comment_reply (cc_id,userid,ccr_content,ccr_time) values(#{cc_id},#{userid},#{ccr_content},now() )" })
	boolean replyComment(CityIntroduceCommentReply cityIntroduceCommentReply);

	/**
	 * 城市点赞
	 * 
	 * @param cityIntroducePraise
	 * @return
	 */
	@Insert({ "insert into c_cityintroduce_praise (userid,c_id) values(#{userid},#{c_id})" })
	boolean praiseCity(CityIntroducePraise cityIntroducePraise);

	/**
	 * 城市介绍评论点赞表
	 * 
	 * @param cityIntroduceCommentPraise
	 * @return
	 */
	@Insert({ "insert into c_cityintroduce_comment_praise (userid,cc_id) values(#{userid},#{cc_id})" })
	boolean commentPraise(CityIntroduceCommentPraise cityIntroduceCommentPraise);

	// ---------------------------------------------------------------------------------------------------------------------------

	/**
	 * 城市管理后台 ，添加城市
	 * 
	 * @param cityIntroduce
	 * @return
	 */
	boolean addCity(CityIntroduce cityIntroduce);

	/**
	 * 后台添加城市图片
	 * 
	 * @param cityIntroducePhoto
	 * @return
	 */
	@Insert({ "insert into c_cityintroduce_photo (cp_photopath,c_id) values( #{cp_photopath}, #{c_id})" })
	boolean addCityPhotos(CityIntroducePhoto cityIntroducePhoto);

	/**
	 * 后台修改城市信息
	 * 
	 * @param cityIntroduce
	 * @return
	 */
	boolean updateCityById(CityIntroduce cityIntroduce);

	/**
	 * 后台修改城市图片
	 * 
	 * @param cityIntroducePhoto
	 * @return
	 */
	@Update({ " update c_cityintroduce_photo set cp_photopath=#{cp_photopath} where c_id=#{c_id}" })
	boolean updateCityPhotos(CityIntroducePhoto cityIntroducePhoto);

	/**
	 * 后台批量删除城市
	 * 
	 * @return
	 */
	boolean batchDelete(@Param("c_id") int[] c_id);

	/**
	 * 后台批量删除城市图片
	 * 
	 * @return
	 */
	@Delete({ "delete from c_cityintroduce_photo where c_id=#{id}" })
	boolean batchDeletePhoto(@Param("id") String id);

	/**
	 * 后台查询所有城市
	 * 
	 * @return
	 */
//	@Select({ "select * from c_cityintroduce" })
	List<CityIntroduce> selectCityIntroduce(@Param("c_inprovince") String c_inprovince);

	/**
	 * 后台查询当前登陆人是否点赞该评论
	 * 
	 * @param userid
	 * @return
	 */
	@Select({ "select * from c_cityintroduce_comment_praise where userid=#{userid}" })
	CityIntroduceCommentPraise ifPraise(@Param("userid") String userid);

	/**
	 * 查询登录人是否点赞该城市
	 * 
	 * @param c_id   城市id
	 * @param userid 登陆人id
	 * @return
	 */
	@Select({ "select count(*) from c_cityintroduce_praise where c_id=#{c_id} and userid=#{userid}" })
	int ifPraiseCityToUserid(@Param("c_id") int c_id, @Param("userid") String userid);
}
